03. Introduction to XML
Introduction to XML
ND079 JPND C3 L2 A03 Introduction To XML V3
XML Objects
XML is a markup language that allows us to define object data using tags. This example describes a person
object with the name
Alex and the age
342. These tags are nested, which means that the name
tag is inside the person
tag. Each element consists of an open tag and a close tag, along with its data. A close tag is the same as the open tag, but begins with a slash(/), so in this example, <name>
is an open tag and </name>
is its closing tag.
<person>
<name>Alex</name>
<age>342</age>
</person>
You can declare lists of objects in XML using repeated tags. This example describes a list of multiple person
objects. Lists in XML must be enclosed by a single parent tag. In this case, that is the persons
tag. Note that all nested tags must be closed before the tag enclosing them can be closed. In this example, that would mean that I cannot close a <person>
tag until both the <name>
and <age>
tags are closed. XML that closes all open tags properly and has only a single element at the top level is considered well-formed.
<persons>
<person>
<name>Alex</name>
<age>342</age>
</person>
<person>
<name>Miles</name>
<age>11</age>
</person>
</persons>
Attributes are a way to represent a nested element inside the definition of its enclosing tag. In the below example, both XML fragments are equivalent.
<person isACat="false">
<name>Alex</name>
<age>342</age>
</person>
<person isACat="false" name="Alex" age="342">
Attribute: A way to represent a nested XML element inside the definition of the enclosing tag.
Tag: The name of an XML element enclosed in angle brackets. <person>
is a person tag.
Element: The combination of a pair of XML tags with its enclosed data.
Well-formed: Well-formed XML has only a single element at the top level. All open tags have a close tag, and all tags close before the tag that encloses them.